package beans;

import java.util.ArrayList;
import java.util.List;

import models.Article;
import models.Photo;
import models.Recommend;

public class RecommendBean {
	public String imageurl;
	public String name;
    public String keyId;
    public String id;
    public long time;

	public static RecommendBean build(Recommend productRecommended){
		RecommendBean bean = new RecommendBean();
		Photo photo = Photo.findById(productRecommended.photo_id);
		if(photo!=null){
		bean.imageurl = photo.getPhoto();
		}
		else{
		bean.imageurl = "";
		}
        bean.id = productRecommended.id;
        bean.time = productRecommended.createTime;
        bean.keyId = productRecommended.keyId;
		bean.name = productRecommended.name;
		return bean;
		
	}
	public static List<RecommendBean> buildList (List<Recommend> plist){
		List<RecommendBean> endlist = new ArrayList<RecommendBean>();
		for(int item = 0;item<plist.size();item++){
			RecommendBean bean = RecommendBean.build(plist.get(item));
			endlist.add(bean);
			
		}
		return endlist;
	}
}
